package com.xxwy.ddu.common.exception;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

/**
 * @author xxwy
 * on 2018/7/30 0030
 */

public abstract class BaseException extends RuntimeException{

    public BaseException() {
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public void handler(ModelMap modelMap){
        modelMap.put("code", getCode());
        if (StringUtils.isNotBlank(getMessage())) {
            modelMap.put("msg", getMessage());
        } else {
            modelMap.put("msg", getMsg(getCode()));
        }
    }

    public String getMsg(Integer code) {
        return HttpCode.msg(code);
    }
    /**
     * 只能由其子类完成
     * @return
     */
    protected abstract Integer getCode();
}
